#pragma once

#include <fstream>
#include <memory>
#include <stdint.h>
#include <string>
namespace Sivin {
  class YUVImage {

  public:
    enum class Format {
      YUV420
    };

    enum class Channel {
      NONE,
      Y,
      U,
      V
    };

    explicit YUVImage();
    explicit YUVImage(int width, int height, Format fmt);
    ~YUVImage();

  public:
    void *getYData() {
      return mYData;
    }

    void *getUData() {
      return mUData;
    }

    void *getVData() {
      return mVData;
    }

    int width() {
      return mWidth;
    }

    int height() {
      return mHeight;
    }

    void *getData(Channel channel) {
      switch (channel) {
        case YUVImage::Channel::Y:
          return mYData;
        case YUVImage::Channel::U:
          return mUData;
        case YUVImage::Channel::V:
          return mVData;
        default:
          return nullptr;
      }
    }

    void setData(char *ydata, char *udata, char *vdata) {
      mYData = ydata;
      mUData = udata;
      mVData = vdata;
    }

  public:
    static std::unique_ptr<YUVImage> loadImage(std::string path, int width, int height, Format format);

  private:
    Format mFormat{YUVImage::Format::YUV420};
    int mWidth;
    int mHeight;
    char *mYData{nullptr};
    char *mUData{nullptr};
    char *mVData{nullptr};
  };
}// namespace Sivin